<!-- 报修列表 -->
<template>
	<div class="app-container">
		<div class="wx-user-box">
			<el-form :inline="true" :model="formInline" class="demo-form-inline">
				<el-form-item label="用户账号"><el-input v-model="formInline.name" clearable placeholder="请输入用户账号查询" @change="sousuo()"></el-input></el-form-item>
				<el-form-item label="物业公司">
					<el-select v-model="formInline.wuye_id" placeholder="请选择" clearable @change="sousuo()">
						<el-option :label="item.wy_name" :value="item.id" v-for="(item, index) in wuyeList" :key="index"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item><el-button type="primary" @click="sousuo()" icon="el-icon-search">查询/筛选</el-button></el-form-item>
			</el-form>

			<el-table :data="tableData" style="width: 100%">
				<el-table-column prop="username" label="用户账号"></el-table-column>
				<el-table-column prop="real_name" label="真实姓名"></el-table-column>
				<el-table-column prop="wy_name" label="所属物业公司"></el-table-column>
				<el-table-column prop="wy_name" label="用户数量"></el-table-column>
				<el-table-column prop="createtime" label="创建时间"></el-table-column>
				<el-table-column label="用户权限">
					<template slot-scope="scope">
						{{userType[scope.row.user_type]}}
					</template>
				</el-table-column>
				<el-table-column label="状态">
					<template slot-scope="scope">
						<el-tag v-if="scope.row.state == 1">正常</el-tag>
						<el-tag v-else-if="scope.row.state == 2" type="info">关闭</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="100px">
					<template slot-scope="scope">
						<el-button type="text" size="small" @click="openInfo(scope.row)">详情</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="el-pagination">
				<el-pagination
					@size-change="handleSizeChange"
					@current-change="handleCurrentChange"
					:current-page="page"
					:page-sizes="[10, 100, 200, 300, 400]"
					:page-size="size"
					layout="total, sizes, prev, pager, next, jumper"
					:total="total"
				></el-pagination>
			</div>
		</div>
	</div>
</template>

<script>
import Api from '@/api/pages/wuye/user.js';
import wuyeApi from '@/api/pages/wuye/wuye.js';
export default {
	name: 'baoxiu-list',
	data() {
		return {
			formInline: {
				name: '',
				wuye_id: '',
				start_time: '',
				end_time: ''
			},
			form: {},
			page: 1,
			size: 10,
			total: 0,
			date: [],
			tableData: [],
			wuyeList: [],
			userType:{
				'1':'超级管理员',
				'2':'普通管理员'
			}
		};
	},
	mounted() {
		this.getData();
		this.getWuyeList();
	},
	methods: {
		getData() {
			let data = {
				pageNumber: this.page,
				pageSize: this.size
			};
			if (this.formInline.name) {
				data['name'] = this.formInline.name.trim();
			}
			if (this.formInline.wuye_id) {
				data['wuye_id'] = this.formInline.wuye_id;
			}
			if (this.date && this.date.length) {
				data['start_time'] = this.date[0];
				data['end_time'] = this.date[1];
			}
			Api.query(data).then(res => {
				if (res.state) {
					this.tableData = res.data.list;
					this.total = res.data.totalRow;
				} else {
					this.$message(res.msg);
				}
			});
		},
		// 修改搜索状态
		upallow(id) {
			Api.upallow({
				xiaoqu_id: id
			}).then(res => {
				if (res.state) {
					this.$message({
					  message: res.msg,
					  type: 'success'
					});
				} else {
					this.$message(res.msg);
				}
				this.getData();
			});
		},
		// 获取物业公司
		getWuyeList() {
			wuyeApi.getWuyeList().then(res => {
				if (res.state) {
					this.wuyeList = res.data;
				} else {
					this.$message(res.msg);
				}
			});
		},
		// 打开修改搜索状态询问
		openShitch(id) {
			this.$confirm('您确定对当前搜索状态进行修改吗?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					this.upallow(id);
				})
				.catch(() => {});
		},
		sousuo() {
			this.page = 1;
			this.getData();
		},
		handleSizeChange(val) {
			console.log(`每页 ${val} 条`);
			this.size = val;
			this.getData();
		},
		handleCurrentChange(val) {
			console.log(`当前页: ${val}`);
			this.page = val;
			this.getData();
		}
	}
};
</script>
<style lang="scss" scoped></style>

<style lang="scss">
.dialogVideo {
	.el-dialog__body {
		padding: 20px;
	}
}
</style>
